package com.chen.springboot.controller;

import com.chen.springboot.common.Result;
import com.chen.springboot.entity.Dict;
import com.chen.springboot.service.impl.DictServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author chenchao
 * @date 2022/6/17 14:11
 */
@RestController
@Api(value = "DictController",tags = "数据字典")
@RequestMapping("/dict")
public class DictController {

    @Autowired
    private DictServiceImpl dictService;


    @PostMapping("/save")
    @ApiOperation(value = "新增字典或者更新")
    public Result addDict(@RequestBody Dict dict){
        return Result.success(dictService.saveOrUpdate(dict));
    }



    @DeleteMapping("/deleteDict/{id}")
    @ApiOperation(value = "删除字典")
    public Result deleteDict(@PathVariable("id") int id){
        return Result.success(dictService.deleteDict(id));
    }


    @RequestMapping("/page")
    @ApiOperation(value = "分页查询")
    public Result selectDict(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "10") Integer pageSize,
                             @RequestParam(defaultValue = "") String name){

        return Result.success(dictService.selectPage(pageNum, pageSize, name));
    }

}
